package com.mop.core.es.dao.plugins.index;

import com.alibaba.fastjson.JSONObject;
import com.lemon.core.common.lang.util.Assert;
import com.lemon.core.common.lang.util.StringUtils;
import com.mop.core.es.dao.util.MappingUtils;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

/**
 * @author lemon
 * @ClassName MappingField
 * @desc
 * @Date 2019/1/5 13:18
 * @Version 1.0
 **/
public class MappingField {

    private String fieldName;

    private FieldType fieldType;

    private String index;

    private String analyzer;

    private String searchAnalyzer;

    private String format;

    private MappingField[] mappingFields = new MappingField[]{};

    public MappingField() {
    }

    public MappingField(String fieldName, FieldType fieldType) {
        this.fieldName = fieldName;
        this.fieldType = fieldType;
    }

    public MappingField(String fieldName, FieldType fieldType, String analyzer, String searchAnalyzer) {
        this.fieldName = fieldName;
        this.fieldType = fieldType;
        this.analyzer = analyzer;
        this.searchAnalyzer = searchAnalyzer;
    }

    public MappingField(String fieldName, MappingField... mappingFields) {
        this.fieldName = fieldName;
        this.mappingFields = mappingFields;
    }

    public String getFieldName() {
        return fieldName;
    }

    public void setFieldName(String fieldName) {
        this.fieldName = fieldName;
    }

    public FieldType getFieldType() {
        return fieldType;
    }

    public void setFieldType(FieldType fieldType) {
        this.fieldType = fieldType;
    }

    public String getIndex() {
        return index;
    }

    public void setIndex(String index) {
        this.index = index;
    }

    public String getAnalyzer() {
        return analyzer;
    }

    public void setAnalyzer(String analyzer) {
        this.analyzer = analyzer;
    }

    public String getSearchAnalyzer() {
        return searchAnalyzer;
    }

    public void setSearchAnalyzer(String searchAnalyzer) {
        this.searchAnalyzer = searchAnalyzer;
    }

    public String getFormat() {
        return format;
    }

    public void setFormat(String format) {
        this.format = format;
    }

    @Override
    public String toString() {
        if (mappingFields.length > 0) {
            return MappingUtils.buildMultiField(fieldName, mappingFields).toString();
        } else {
            return MappingUtils.buildSingleField(this).toString();
        }
    }


    public static void main(String[] args) {
        MappingField mappingField = new MappingField();
        mappingField.setFieldName("name");
        mappingField.setFieldType(FieldType.STRING_TEXT);
        System.out.println(mappingField.toString());
    }
}
